<%-- 
    Document   : StudentsList
    Created on : 01.03.2012, 14:37:45
    Author     : Alexey Akimov <frinatella@gmail.com>
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="student_report.DbConnection"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Students List</title>
    </head>
    <body>
        <h1>Students List</h1>
        <table border="1"><tr><td>Student Id</td><td>Surname</td><td>Name</td><td>Group number</td></tr>
        <%
         try {
                Connection connection = DbConnection.getConnection();
                ResultSet resultSet = connection.createStatement().executeQuery("select STUDENT_ID, SURNAME, NAME, GROUP_NUMBER from STUDENTS");
                String href, studentId, surname, name, groupNumber;
                while (resultSet.next()) {
                    studentId = resultSet.getString("STUDENT_ID");
                    surname = resultSet.getString("SURNAME");
                    name = resultSet.getString("NAME");
                    groupNumber = resultSet.getString("GROUP_NUMBER");
                    href = "href=\"MarksForStudentsList.jsp?studentId=" + studentId + "&surname=" + surname + "&name=" + name + "&groupNumber=" + groupNumber + "\"";
                    out.println("<tr><td><a " + href + ">" + studentId + "</a></td>"
                            + "<td><a " + href + ">" + surname + "</a></td>"
                            + "<td><a " + href + ">" + name + "</a></td>"
                            + "<td><a " + href + ">" + groupNumber + "</a></td></tr>");
                }
                } catch (SQLException ex) {
                    out.print("<h3>Students list loading failed.</h3>");
                }
        %>
        </table>     
    </body>
</html>

